import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: ()=>import('@/views/Home.vue'),
    meta: {
      index: '1',
      title: '无限可能 - 首页',
    }
  },
  {
    path: '/About',
    name: 'about',
    component: ()=>import('@/views/About.vue'),
    meta: {
      index: '2',
      title: 'About',
    }
  },

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => { //beforeEach是router的钩子函数，在进入路由前执行
  if (to.meta.title) { //判断是否有标题
      document.title = to.meta.title
  }
  next() //执行进入路由，如果不写就不会进入目标页
})

export default router
